package model;

import java.util.Arrays;

//adds item to list of equipped item of entity. If there is no space then return false
public class EquippableItem extends TakeableItem{
	public boolean equip(Entity e, Item i)
	{
		Item[] items = e.getEquippedItems();
		int counter = 0;
		while(counter < items.length && items[counter] != null)
		{
			counter++;
		}
		if(counter < items.length)
		{
			items[counter] = i;
			return true;
		}
		return false;
	}
	
	//takes the item out of the list from entity. Not sure what to do with the item. just returning item if found
	//Return null if not found
	public Item unequip(Entity e, Item i)
	{
		Item itemFound = null;
		Item[] items = e.getEquippedItems();
		int index = Arrays.binarySearch(items, i);
		if(index >= 0)
		{
			itemFound = items[index];
			for(int j = index; j < items.length-1; j++)
			{
				items[j] = items[j+1];
			}
			items[items.length-1] = null;
		}
		
		return itemFound;
	}
}
